import pymysql



def addUser():
    # 打开数据库连接
    db = pymysql.connect (host="10.103.252.55", user="admin", password="Admin_12345", database="jyy_ams_amo_org", charset='utf8')
    db2 = pymysql.connect (host="10.103.252.55", user="admin", password="Admin_12345", database="jyy_ams_customer", charset='utf8')

    # 使用 cursor() 方法创建一个游标对象 cursor
    cursor = db.cursor ()
    cursor2 = db2.cursor ()
    mobile = 16666666666
    id = 1000
    # for i in range (0, 3000):
    #     print(i)
    #     sql = "INSERT INTO  t_homer_user (uc_id,user_name,mobile,email,open_id,create_time,is_deleted) VALUES (%s,'%s','%s','sunlinpeng@jinyiyun.com','%s',NOW(),0);" %(
    #         id, "开盘并发" + str (id), str (mobile),str (mobile))  # 用户表
    #     # 使用 execute()  方法执行 SQL 查询
    #     try:
    #         # 执行SQL语句
    #         cursor.execute (sql)
    #         # 提交到数据库执行
    #         db.commit ()
    #     except Exception as e:
    #         print(e)
    #         # 发生错误时回滚
    #         db.rollback ()
    #     mobile += 1
    #     id += 1
    #     # # 使用 fetchone() 方法获取单条数据.
    #     # data = cursor.fetchone ()

    sql2 = "SELECT homer_user_id FROM `t_homer_user` WHERE create_time>='2021-02-23';"
    cursor.execute (sql2)
    data = cursor.fetchall ()
    #分界线--------------------------------------
    # sql5 = "SELECT auth_user_id,user_id FROM `t_user_auth` WHERE create_time>='2021-02-23';"
    # cursor2.execute (sql5)
    # data = cursor2.fetchall ()
    for i in data:
        print (i[0], i[1])
        # sql3 = "INSERT INTO `t_user_auth` (user_id,user_name,cert_no,bank_account,mobile,email,anxin_sign_user_id,is_agree,is_deleted,create_time) VALUES (%s,'并发数据','411303198908095118','123321','13058019302','sunlinpeng@jinyiyun.com',%s,1,0,NOW());" % (
        # i[0], str (mobile)) # 业主认证表
        sql4 = "INSERT INTO `t_customer_auth` (user_id,user_name,cert_no,STATUS,project_id,project_name,auth_user_id,city_code,city_name,is_agree,is_deleted,create_time) VALUES (%s,'开盘并发数据','411303198908095118',1,44,'智能回归项目601号',%s,1201,'天津市',1,0,NOW());" % (
        i[1],i[0])
        cursor2.execute (sql4)
        db2.commit ()

    print ("执行完成")

    # 关闭数据库连接
    db.close ()


if __name__ == '__main__':
    addUser ()
